*Individual item panel coding (no multi-item scales)*


*to do
*add aid to Blacks in 1994-1996 -has party placements
*might be other items in 1994-1996, such as ideology
* Patterson 1976 has abortion in waves three and five, maybe defense


*cd "/Users/vetsean/Google Drive/Issue Voting measurement error/Main findings"
*This code creates all possible four-item economic scales
clear all
global no_takers 0 // 1 = no takers excluded from knowledge
/*
global factor 1 // 1 = factor scores vs simple average
global standardized 0 // 1 = means zero, standard deviation one
global missing = . // Set missing value. All coded to 7-point scales, so 4 is midpoint
                     // Need to remain consistent about that when adding new panels
global ktype 1 // 1 normal knowledge coding
*/
 global studies Econ_SSI1516  All_92_96   Econ_7276  Econ_BES9295 Econ_BES9296 Econ_BES9297 Econ_BES9701 Econ_76 Econ_94_96  

capture program drop norm					 
program define norm
 summarize  `1'
 replace `1' = (`1'-r(min))/(r(max)-r(min))
 summarize  `1'
end
					 

					 
*********************************************************************
**************SSI 2015-16 panel **********************************************

*stability
 use Data/ssi, clear
*set variables 
global issues foodstamps minwage schools ss medicare housing childcare debtceiling parentleave services
global issues2 gun health affact immigration tax gay climate israel flag
global issues3 foodstamps minwage schools ss medicare housing childcare debtceiling parentleave services gun health affact immigration tax gay climate israel flag
global year_1 1
global year_2 2
global study Econ_SSI1516
global ni 10
g ID = 1516000+ _n  //Numeric  _n
g gk=(soph)

*All issues scaled so higher values are conservative, all on seven-point scale
for any $issues : rename place_X_self$year_1 st_X_$year_1 \ rename place_X_self$year_2 st_X_$year_2
for any $issues : replace st_X_$year_1= st_X_$year_1 * 6+1 \ replace st_X_$year_2=st_X_$year_2 * 6+1
for any $issues :  g missing_X_1 =  st_X_$year_1 == 595 \ g missing_X_2 =  st_X_$year_2 == 595
for any $issues : recode st_X_$year_1 st_X_$year_2 (595 = $missing ) 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

destring iss_gun_know2-iss_flag_know2, replace i("NA")

*drop people who correctly placed the candidates in one way but not the other
*rename position knowledge
for any $issues: destring place_X_dem2, ignore("NA") replace \ destring place_X_rep2, ignore("NA") replace 
for any $issues: g lp_X_$year_1 = round((place_X_dem*6)+1,1) \ g lp_X_$year_2 = round((place_X_dem2*6)+1,1) // positions of left candidate/party
for any $issues: g rp_X_$year_1 = round((place_X_rep*6)+1,1) \ g rp_X_$year_2 = round((place_X_rep2*6)+1,1) // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2 (595=-99) // always use -99 for dk
sum lp_* rp_*
tab1 lp_* rp_*

*code party so Conservative Party = 1, other/none = 0.5, liberal party = 0
recode party 1/3 =0 5/7=1  4 8 = .5,g  (PID_1)
recode party 1/3 =0 5/7=1  4 8 = .5,g  (PID_2)
g weight=1

*candidate/party approval/feeling thermometer coded to vary between 0-1
g net_feel_1 = ((feel_dem - feel_rep)+4)/8  // I think these are backward coded so that higher values mean less support for the party
g net_feel_2 = ((feel_dem2 -feel_rep2)+4)/8  // dito, so these now have higher values with more support for the conservative party
g therm_1 = net_feel_1
g therm_2 = net_feel_2
g vote_1 = net_feel_1 > 0.5 if net_feel_1 <. // only asked vote for part of the sample in wave 1, so substitute feelings to monomer from wave 6
g vote_2 =net_feel_2 > 0.5 if net_feel_2 <.
g kpideo =.
corr PID_1 PID_2 net_feel_1 net_feel_2 therm_1 therm_2 feel_rep   feel_dem  feel_rep2 feel_dem2 
sum PID_1 PID_2 net_feel_1 net_feel_2 therm_1 therm_2 feel_rep   feel_dem  feel_rep2 feel_dem2 
do stability_coding_ind.do
sum PID_1 PID_2  therm_1 therm_2 scale_* vote_* k_scale
bys issues_scale:sum PID_1 PID_2  therm_1 therm_2 scale_* vote_* k_scale
corr PID_1 PID_2 therm_1 therm_2 scale_* vote_*

				 
*********************************************************************
**************all 92-96  policy **********************************************
*stability
 do ANES_92_96.do
*set variables 
global issues gss job def ide abr  
global year_1 92
global year_2 96
global study All_92_96
global ni 5
g ID = VCASEID*100
g gk=(kg_total)

for any $issues : rename X_92 st_X_92 \ rename X_96 st_X_96 
for any $issues :  g missing_X_1 =  st_X_$year_1 == -99 \ g missing_X_2 =  st_X_$year_2 == -99
for any $issues : recode st_X_$year_1 st_X_$year_2 (-99 = $missing ) 
corr st_*_$year_1
factor st_*_$year_1,pcf
sum st_*_$year_1
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any $issues: g lp_X_$year_1 = c_X_$year_1 \ g lp_X_$year_2 = c_X_$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = b_X_$year_1 \ g rp_X_$year_2 = b_X_$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2 (8=-99) // always use -99 for dk
sum lp_* rp_*
tab1 lp_* rp_*

g PID_1 = PID_$year_1 *6+1
g PID_2 = PID_$year_2 *6+1
tab1 PID_*
corr PID_*
recode PID_* (1/3 =0) (4 = 0.5) (5/7 = 1)
g weight=V960004 
g therm_92 = (Bush_92-Clinton_92+1)/2
g therm_96 = (Dole_96-Clinton_96+1)/2 
g vote_1 = vote_92 
g vote_2 =vote_96 
sum d_ide* r_ide*
g kpideo = d_ide_$year_1 < r_ide_$year_1 & d_ide_$year_1 !=8 & r_ide_$year_1 !=8 /// 
         & d_ide_$year_2 < r_ide_$year_2 & d_ide_$year_2 !=8 & r_ide_$year_2 !=8 if r_ide_$year_1 <. & r_ide_$year_2 <. & d_ide_$year_1 <. & d_ide_$year_2 <.
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_* kpideo
do stability_coding_ind.do
sum scale_1 scale_2 total_knowledge k_scale gk NUM_issues therm_*


*********************************************************************
**************94-96 three-item economic**********************************************
*stability
 do ANES_92_96.do
*set variables 
global issues gss job health  
global year_1 94
global year_2 96
global study Econ_94_96
global ni 3
g ID =  VCASEID*100
g gk=(kg_total)

for any $issues : rename X_94 st_X_94 \ rename X_96 st_X_96 
for any $issues :  g missing_X_1 =  st_X_$year_1 == -99 \ g missing_X_2 =  st_X_$year_2 == -99
for any $issues : recode st_X_$year_1 st_X_$year_2 (-99 = $missing ) 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
drop c_gss_94  c_job_94   c_health_94 // drop since we are substituting party
for any $issues: g c_X_94 = d_X_94 \ g b_X_94 = r_X_94  // no candidate placements in 1994 so substitute party placements
for any $issues: g lp_X_$year_1 = c_X_$year_1 \ g lp_X_$year_2 = c_X_$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = b_X_$year_1 \ g rp_X_$year_2 = b_X_$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2 (8=-99) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*

g PID_1 = PID_$year_1 *6+1
g PID_2 = PID_$year_2 *6+1
tab1 PID_*
corr PID_*
recode PID_* (1/3 =0) (4 = 0.5) (5/7 = 1)
g weight=V960004 
g therm_94 = (Dole_94-Clinton_92+1)/2
g therm_96 = (Dole_96-Clinton_96+1)/2 
sum d_ide* r_ide*
g vote_1 = PID_1 // substitute because no vote in 1994, thermometers are missing for many in 1994
g vote_2 = vote_96 
g kpideo = d_ide_$year_2 < r_ide_$year_2 & d_ide_$year_2 !=8 & r_ide_$year_2 !=8 if  r_ide_$year_2 <.  & d_ide_$year_2 <.
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_* kpideo
do stability_coding_ind.do


*********************************************************************
**************Economic 7276**********************************************
*stability
 do anes72_76.do

*set variables 
global issues aid job tax wmn bus pot rts  // excluding insurance because it complicates the analysis
global year_1 72
global year_2 76
global study Econ_7276
global ni 7
recode V720002 0 =. 
g ID = 7276000+  V720002
g gk=(knw_total)
for any $issues : rename X72  st_X_72 \ rename X76 st_X_76 
sum st_*_7*
for any $issues :  g missing_X_1 =  st_X_$year_1 == -99 \ g missing_X_2 =  st_X_$year_2 == -99
for any $issues : recode st_X_$year_1 st_X_$year_2 (-99 = $missing ) 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2
sum s_*_76
corr s_*_76

*placement knowledge -unfortunately, the party questions were on opposite forms,
for any $issues: g lp_X_$year_1 = d_X$year_1 \ g lp_X_$year_2 = d_X$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = r_X$year_1 \ g rp_X_$year_2 = r_X$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2 (8=-99) (0 9 =.) // always use -99 for dk
sum lp_* rp_*

g PID_1 = pid$year_1 *6+1
g PID_2 = pid$year_2 *6+1
tab1 PID_*
corr PID_*
recode PID_* (1/3 =0) (4 = 0.5) (5/7 = 1)
g weight=1 // no real weight variable 
g vote_1 =pvote72 // neither of these include pre-election vote for those not interviewed in the postelection
g vote_2 =pvote76
sum d_ide* r_ide*
g kpideo = d_ide_$year_1 < r_ide_$year_1 & d_ide_$year_1 !=8 & r_ide_$year_1 !=8 /// 
         & d_ide_$year_2 < r_ide_$year_2 & d_ide_$year_2 !=8 & r_ide_$year_2 !=8 if r_ide_$year_1 <9 & r_ide_$year_2 <9 & d_ide_$year_1 <9 & d_ide_$year_2 <9 & r_ide_$year_1 >0 & r_ide_$year_2 >0 & d_ide_$year_1> 0 & d_ide_$year_2 >0
corr  s_*
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_* kpideo

do stability_coding_ind.do

*********************************************************************
**************Patterson**********************************************
*stability
 do Patterson_v0_7.do
*set variables 
*only 36 people get abortion right so drop
for any abr: tab X_3 \  tab X_5  \  tab X_c_5  \  tab X_f_5 
global issues jobs price spd tax  // unfortunately they don't ask about price control positions in wave 1
global year_1 3
global year_2 5
global study Econ_76
global ni 4

g ID = 7676000 + _n
*g gk=(gk)

tab jobs_5 jobs_3, mis
for any $issues : recode X_3 (0 9=.) (8 = -99), gen(st_X_3) \ recode X_5 (0 9=.) (8 = -99), gen(st_X_5) 
for any $issues :  drop X_3 \ drop X_5 
replace st_tax_3 = 8 - st_tax_3 if st_tax_3 > -99
replace st_tax_5 = 8 - st_tax_5 if st_tax_5 > -99
for any $issues :  g missing_X_1 =  st_X_$year_1 == -99 \ g missing_X_2 =  st_X_$year_2 == -99
for any $issues : recode st_X_$year_1 st_X_$year_2 (-99 = $missing ) 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any c f : replace tax_X_3 = 8 - tax_X_3 if tax_X_3 >0 & tax_X_3 <8  // reverse code so higher values are more conservative
for any c f : replace tax_X_5 = 8 - tax_X_5 if tax_X_5 >0 & tax_X_5 <8  // reverse code so higher values are more conservative
for any $issues: g lp_X_$year_1 = X_c_$year_1 \ g lp_X_$year_2 = X_c_$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = X_f_$year_1 \ g rp_X_$year_2 = X_f_$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2 (8=-99) (0 9 =.) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*


replace PID_1 = PID_$year_1  *6+1
replace PID_2 = PID_$year_2  *6+1
tab1 PID_*
corr PID_*

recode PID_1 PID_2 (1/3 =0) (4 = 0.5) (5/7 = 1)
drop PID_3 PID_4 PID_5

capture drop therm_1 therm_2

replace weight=weight/100
g vote_1 =vote_4 // No vote question in wave 3, I think
g vote_2 =vote_5
sum ideo_d_* ideo_r_*
g kpideo = ideo_d_$year_1 < ideo_r_$year_1 & ideo_d_$year_1 !=8 & ideo_r_$year_1 !=8 /// 
         & ideo_d_$year_2 < ideo_r_$year_2 & ideo_d_$year_2 !=8 & ideo_r_$year_2 !=8 if ideo_r_$year_1 <9 & ideo_r_$year_2 <9 & ideo_d_$year_1 <9 & ideo_d_$year_2 <9&ideo_r_$year_1 >0 & ideo_r_$year_2 >0 & ideo_d_$year_1 >0 & ideo_d_$year_2 >0
sum vote_1 vote_2 PID_1 PID_2 therm_* s_* kpideo gk
correlate gk kpideo
corr vote_1 vote_2 PID_1 PID_2 therm_* s_* 

do stability_coding_ind.do
*********************************************************************
**************British election study 97-01**********************************************
do "BES 1997-2001_v2.do"  //only 97 and 01 waves asked all four economic questions and placements
*set variables 
global issues jbp txs prn ieq  // first three asked every wave, ieq not asked in 1994
global year_1 97
global year_2 01
global study Econ_BES9701
global ni 4

g ID = 9700000+ serialno
g gk=(general_knowledge)
for any $issues :  g missing_X_1 =  s_X_$year_1 == -99 \ g missing_X_2 =  s_X_$year_2 == -99
for any $issues : g st_X_$year_1= (s_X_$year_1-1)*.6+1 if s_X_$year_1 >-99 \ drop s_X_$year_1
for any $issues : g st_X_$year_2= (s_X_$year_2-1)*.6+1 if s_X_$year_2 >-99 \ drop s_X_$year_2
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any $issues: g lp_X_$year_1 = labX$year_1 \ g lp_X_$year_2 = labX$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = conX$year_1 \ g rp_X_$year_2 = conX$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -8/-1  99=.) (12 = 1) (13 =11) ( 98 = -99) // always use -99 for dk
for any $issues : replace lp_X_$year_1= (lp_X_$year_1-1)*.6+1 \ replace lp_X_$year_2= (lp_X_$year_2-1)*.6+1 // convert to seven-point scale
for any $issues : replace rp_X_$year_1= (rp_X_$year_1-1)*.6+1 \ replace rp_X_$year_2= (rp_X_$year_2-1)*.6+1 // convert to seven-point scale
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -59 = -99) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*

g PID_1 = PID_$year_1
g PID_2 = PID_$year_2 
sum PID_1 PID_2 therm_* s_*
g vote_1 =vote_97 // No vote question in wave 3, I think
g vote_2 =vote_01
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_*
g kpideo = .
do stability_coding_ind.do
*********************************************************************
**************British election study**********************************************
 do BES_0_2.do
*set variables 
global issues jbp txs prn ieq eci // first three asked every wave, ieq not asked in 1994
global year_1 92
global year_2 95
global study Econ_BES9295
global ni 5
g ID = ${year_1}00000+ serialno // these need to be the same for all the 1992-1997 waves
g gk=(general_knowledge)

for any $issues :  g missing_X_1 =  s_X_$year_1 == -99 \ g missing_X_2 =  s_X_$year_2 == -99
for any $issues : g st_X_$year_1= (s_X_$year_1-1)*.6+1 if s_X_$year_1 >-99  \ drop s_X_$year_1  // convert to seven-point scale
for any $issues : g st_X_$year_2= (s_X_$year_2-1)*.6+1 if s_X_$year_2 >-99  \ drop s_X_$year_2 // convert to seven point scale
for any $issues : recode st_X_$year_1 st_X_$year_2 (-99 = $missing) 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any $issues: g lp_X_$year_1 = labX$year_1 \ g lp_X_$year_2 = labX$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = conX$year_1 \ g rp_X_$year_2 = conX$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -8/-1  99=.) (12 = 1) (13 =11) (97 98 = -99) // always use -99 for dk
for any $issues : replace lp_X_$year_1= (lp_X_$year_1-1)*.6+1 \ replace lp_X_$year_2= (lp_X_$year_2-1)*.6+1 \ replace rp_X_$year_1= (rp_X_$year_1-1)*.6+1 \ replace rp_X_$year_2= (rp_X_$year_2-1)*.6+1 // convert to seven-point scale
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -59 = -99) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*

g PID_1 = PID_$year_1
g PID_2 = PID_$year_2 
corr PID_1 s_*_92 therm_92
corr PID_2 s_*_95 therm_95
sum  PID_1 s_*_92 therm_92 PID_2 s_*_95 therm_95
g vote_1 =vote_92 // No vote question in wave 3, I think
g vote_2 =vote_95
g kpideo = .
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_*
do stability_coding_ind.do

*********************************************************************
**************British election study**********************************************
 do BES_0_2.do
*set variables 
global issues jbp txs prn ieq eci // first three asked every wave, ieq not asked in 1994
global year_1 92
global year_2 96
global study Econ_BES9296
global ni 5

g ID = ${year_1}00000+ serialno // these need to be the same for all the 1992-1997 waves
g gk=(general_knowledge)

for any $issues :  g missing_X_1 =  s_X_$year_1 == -99 \ g missing_X_2 =  s_X_$year_2 == -99
for any $issues : g st_X_$year_1= (s_X_$year_1-1)*.6+1 if s_X_$year_1 >-99 \ drop s_X_$year_1
for any $issues : g st_X_$year_2= (s_X_$year_2-1)*.6+1 if s_X_$year_2 >-99 \ drop s_X_$year_2
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any $issues: g lp_X_$year_1 = labX$year_1 \ g lp_X_$year_2 = labX$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = conX$year_1 \ g rp_X_$year_2 = conX$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -8/-1  99=.) (12 = 1) (13 =11) (97 98 = -99) // always use -99 for dk
for any $issues : replace lp_X_$year_1= (lp_X_$year_1-1)*.6+1 \ replace lp_X_$year_2= (lp_X_$year_2-1)*.6+1 \ replace rp_X_$year_1= (rp_X_$year_1-1)*.6+1 \ replace rp_X_$year_2= (rp_X_$year_2-1)*.6+1 // convert to seven-point scale
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -59 = -99) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*

g PID_1 = PID_$year_1
g PID_2 = PID_$year_2 
corr PID_1 s_*_92 therm_92
corr PID_2 s_*_96 therm_96
sum  PID_1 s_*_92 therm_92 PID_2 s_*_96 therm_96
g vote_1 =1-vote_92 // No vote question in wave 3, I think
g vote_2 =1-vote_96
g kpideo = .
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_*

do stability_coding_ind.do
*********************************************************************
**************British election study**********************************************
*Does general knowledge of positions or specific knowledge of positions better explain
*stability
 do BES_0_2.do
*set variables 
global issues jbp txs prn ieq eci // first three asked every wave, ieq not asked in 1994
global year_1 92
global year_2 97
global study Econ_BES9297
global ni 5

g ID = ${year_1}00000+ serialno // these need to be the same for all the 1992-1997 waves
sum ID
g gk=(general_knowledge)
for any $issues : tab s_X_$year_1
for any $issues :  g missing_X_1 =  s_X_$year_1 == -99 \ g missing_X_2 =  s_X_$year_2 == -99
for any $issues : g st_X_$year_1= (s_X_$year_1-1)*.6+1 if s_X_$year_1 >-99 \ drop s_X_$year_1
for any $issues : g st_X_$year_2= (s_X_$year_2-1)*.6+1 if s_X_$year_2 >-99 \ drop s_X_$year_2
for any $issues : sum st_X_$year_1 st_X_$year_2 
for any $issues : rename st_X_$year_1 s_X_$year_1 \ rename st_X_$year_2 s_X_$year_2

*placement knowledge
for any $issues: g lp_X_$year_1 = labX$year_1 \ g lp_X_$year_2 = labX$year_2 // positions of left candidate/party
for any $issues: g rp_X_$year_1 = conX$year_1 \ g rp_X_$year_2 = conX$year_2 // positions of right candidate/party
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -8/-1  99=.) (12 = 1) (13 =11) (97 98 = -99) // always use -99 for dk
for any $issues : replace lp_X_$year_1= (lp_X_$year_1-1)*.6+1 \ replace lp_X_$year_2= (lp_X_$year_2-1)*.6+1 \ replace rp_X_$year_1= (rp_X_$year_1-1)*.6+1 \ replace rp_X_$year_2= (rp_X_$year_2-1)*.6+1 // convert to seven-point scale
for any $issues: recode lp_X_$year_1 lp_X_$year_2 rp_X_$year_1  rp_X_$year_2  ( -59 = -99) // always use -99 for dk
tab1 lp_* rp_*
sum lp_* rp_*

g PID_1 = PID_$year_1
g PID_2 = PID_$year_2 
corr PID_1 s_*_92 therm_92
corr PID_2 s_*_97 therm_97
sum  PID_1 s_*_92 therm_92 PID_2 s_*_97 therm_97
g vote_1 =1-vote_92 // No vote question in wave 3, I think
g vote_2 =1-vote_97
g kpideo = .
corr vote_1 vote_2 PID_1 PID_2 therm_* s_*
sum vote_1 vote_2 PID_1 PID_2 therm_* s_*

do stability_coding_ind.do

****************COMBINE FILES******************************************* BES_66_70
global studies2  Econ_SSI1516  All_92_96     Econ_BES9295 Econ_BES9296 Econ_BES9297 Econ_BES9701 Econ_76 Econ_94_96 
use Data/temporary/stability_pooled_ind_Econ_7276, clear
for any $studies2: append using Data/temporary/stability_pooled_ind_X, 
drop if total_knowledge ==.
drop if gk ==.
*drop if scale_1 ==.
*drop if scale_2 ==.
*g k_percent =round(k_scale/NUM_issues, .25)
g k_percent =k_scale/NUM_issues
*xtile gk_6 = gk,n(6)
*xtile gk_3 = gk,n(3)
g gk_5 =.
for any $studies :xtile gk_X_5 = gk if study == "X",n(5)
for any $studies :replace  gk_5 =gk_X_5 if study == "X" \ drop gk_X_5
g gk_10 =.
for any $studies :xtile gk_X_10 = gk if study == "X",n(10)
for any $studies :replace  gk_10 =gk_X_10 if study == "X" \ drop gk_X_10
g gkn =.
for any $studies : sum gk if study == "X" \  replace gkn = (gk-r(min))/(r(max)-r(min)) if study == "X"
g independent = PID_1 ==.5 | PID_2 == .5 if PID_1!=. & PID_2!=.
g partisan =independent == 0 if independent !=.
g stable_PID =PID_1 == PID_2  if PID_1!=. & PID_2!=.
for any $studies: egen therm_1X=std(therm_1)  if study == "X"
g scale_therm=.
for any $studies: replace scale_therm= abs(scale_1-therm_1X)  if study == "X" \ drop therm_1X
g therm_switch= ((therm_1<.5 & therm_2 >.5 & therm_2 <.)  | (therm_1>.5& therm_2<.5 & therm_1 <.) ///
              | (therm_1==.5 & therm_2!=.5 & therm_2 <.)| (therm_2== .5& therm_1!=.5 & therm_1 <.))
recode therm_switch	 1 = 0 0 = 1,gen( therm_stable)	  

tab study,g(study_n)

replace total_knowledge= round(total_knowledge,1)
for any ins aid job jobs price spd tax jbp txs prn ieq:g issue_X = regex(issues_scale, "X")
g agree_candidate = scale_1>4 & therm_1 > 0.5 | scale_1<4 & therm_1<0.5  if scale_1 <. & scale_2 <. & PID_1<.
g agree_party = scale_1>4 & PID_1==1 | scale_1<4 & PID_1==0  if scale_1 <. & scale_2 <. & PID_1<.
g agree = agree_candidate == 1 | agree_party == 1 if agree_candidate<. | agree_party<.
g disagree_candidate = scale_1<4 & therm_1 > 0.5 | scale_1>4 & therm_1<0.5  if scale_1 <. & scale_2 <. & PID_1<.
g disagree_party = scale_1<4 & PID_1==1 | scale_1>4 & PID_1==0  if scale_1 <. & scale_2 <. & PID_1<.
g disagree = disagree_candidate == 1 | disagree_party == 1 if disagree_candidate<. | disagree_party<.

*only three individuals in 2008 placed all the candidates correctly (seven correct) , so
egen within_SD =rowsd(scale_1 scale_2)

bys study: tab total_knowledge if NUM_issues == 1
replace total_knowledge = 6 if total_knowledge == 7 & study =="All_08"
replace total_knowledge = 6 if total_knowledge == 7 & study =="All_7276"
replace total_knowledge=0 if study =="Econ_SSI1516" & (total_knowledge==1)
replace total_knowledge=1 if study =="Econ_SSI1516" & (total_knowledge==2 |total_knowledge==3 )
replace total_knowledge=2 if study =="Econ_SSI1516" & (total_knowledge==4 |total_knowledge==5 )
replace total_knowledge=3 if study =="Econ_SSI1516" & (total_knowledge==6 |total_knowledge==7  )
replace total_knowledge=4 if study =="Econ_SSI1516" & (total_knowledge==8 )
replace total_knowledge=5 if study =="Econ_SSI1516" & (total_knowledge==9 )
replace total_knowledge=6 if study =="Econ_SSI1516" & (total_knowledge==10 )

g total_issues2 = total_issues
replace total_issues2 = 6 if study =="Econ_SSI1516"
replace total_issues2 = 6 if study =="All_7276"
replace total_issues2 = 6 if study =="All_08"
replace total_issues2 = 4 if study =="Econ_76"

g placement_percent = round(total_knowledge/total_issues2*100, 25)
g placement_percentnr = total_knowledge/total_issues2*100
g tk_percent = round(total_knowledge/total_issues2*100 , 25)
*these should all be roughly 1-7:
 sum scale_* 
 bys study: sum scale_* 

  g issue = issues_scale
 encode issue,g(issuen)
 egen study_issue = group(study issue)


*create a attitude response with no variation across individuals
egen scale_mean = mean((scale_1+scale_2)/2), by(study issue)
egen scale_SD = sd((scale_1+scale_2)/2), by(study  issue)
replace scale_SD = 1 if scale_SD <.1
*egen scale_2_mean = mean(scale_2), by(study ID)
*egen scale_2_SD = sd(scale_2), by(study ID)
g scale_1_s = (scale_1 - scale_mean)
g scale_2_s = (scale_2 - scale_mean)
 sum scale_*
 
 table study,c(mean scale_1_s)
 
label variable k_scale "Number of correct placements in scale"
label variable total_knowledge "Total number of issues correct"
label variable NUM_issues "Number of issues in scale"
label variable k_percent "Correctly placed issue % in scale"
 label variable gk_5 "General knowledge quintiles"
sum  scale_1 scale_2 crystallized change gk k_percent
 *should be no duplicates
 duplicates list ID study issue

*these should all be exactly 0-1:
 sum  therm_1 therm_2 PID_1 PID_2
 bys study: sum therm_1 therm_2 
 compress
save Data/stability_ind_std${standardized}ktype${ktype}fct${factor} , replace
